# -*- coding:UTF-8 -*- #

import os
from multiprocessing import Process, Pool
import time

"""pool方法"""
def worker(x):
    for j in range(1, 11):
        print("%d:%d" % (x, j))
        time.sleep(1)

pool = Pool(3)
for i in range(1, 11):
    pool.apply_async(worker, (i,))
pool.close() # 关闭进程池，不允许继续添加进程
pool.join() # 等待进程池中的所有进程结束

"""Process方法"""
# class MyProcess(Process):
#     def __init__(self, name):
#         super(MyProcess, self).__init__()
#         self.name = name
#     def run(self):
#         print('process name :' + str(self.name))
#         time.sleep(1)
# if __name__ == '__main__':
#     for i in range(3):
#         p = MyProcess(str(i))
#         p.start()

# def show():
#     print("子进程 ")
#
# if __name__ == "__main__":
#     proc = Process(target=show)
#     print(proc)
#     proc.start()
#     proc.join()


"""os.fork()"""
# ret = os.fork()
# if ret ==0 :
#     print("子进程ret="+str(ret) + ";pid=%d" % (os.getpid()))
# else:
#     print("父进程ret="+str(ret)+"; pid=%d"%(os.getpid())+";")
